package com.zzvcom.webapp.action.example;

import java.io.UnsupportedEncodingException;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.zzvcom.persist.model.user.User;
import com.zzvcom.service.UserManager;
import com.zzvcom.template.ResultPage;

@Controller
@Scope("prototype")
public class RestUserAction implements ModelDriven<User>, Preparable
{
    private User user;

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    private UserManager userManager;

    private ResultPage resultPage;

    private String str;

    public void test() throws UnsupportedEncodingException
    {
        str = new String(str.getBytes("ISO8859-1"), "UTF-8");
        System.out.println(str);
    }

    public String execute()
    {

        if (user != null)
        {
            System.out.println(user.getUsername());

        }
        if (resultPage == null)
        {
            resultPage = new ResultPage();
        }

        resultPage.setDetachedCriteria(DetachedCriteria.forClass(User.class));
        userManager.getResultPageByDetachedCriteria(resultPage);

        // resultPage.setHql("FROM User", null);
        // userManager.getResultPageByHQL(resultPage);

        return "list";
    }

    public void prepare() throws Exception
    {
        user = new User();
    }

    public User getModel()
    {
        return user;
    }

    public User getUser()
    {
        return user;
    }

    public void setUser(User user)
    {
        this.user = user;
    }

    public UserManager getUserManager()
    {
        return userManager;
    }
    @Autowired
    public void setUserManager(UserManager userManager)
    {
        this.userManager = userManager;
    }

    public ResultPage getResultPage()
    {
        return resultPage;
    }

    public void setResultPage(ResultPage resultPage)
    {
        this.resultPage = resultPage;
    }

    public String getStr()
    {
        return str;
    }

    public void setStr(String str)
    {
        this.str = str;
    }
    
    

}
